package service

import (
	"Im/dao"
	"Im/dto"
	"Im/global"
	"Im/model"
	"errors"
)

func ImUserLoginService(dto dto.ImUserLoginDto) (error, model.ImUser) {
	err, user := dao.ImUserLogin(dto.Account, dto.Password)
	return err, user
}

func ImUserSignUp(signDto dto.ImUserSignDto) error {
	//校验用户传来的验证码是否正确
	if global.EmailCode[signDto.Email] != signDto.EmailCode {
		return errors.New("验证码错误")
	}
	//首先要查询账号是否存在
	_, err := dao.ImUserSignUp(signDto)
	if err != nil {
		return err
	}

	//注册完毕，将保存的验证码删除
	delete(global.EmailCode, signDto.Email)
	return nil
}
